<template>
  <el-container class="layout-container">
    <!-- 桌面版导航 -->
    <el-header class="header desktop-only">
      <div class="logo">
        AI绘画工作流
      </div>
      <el-menu
        mode="horizontal"
        :router="true"
        :default-active="route.path"
        class="desktop-menu"
      >
        <el-menu-item index="/">首页</el-menu-item>
        <el-menu-item index="/workflow/list">工作流管理</el-menu-item>
      </el-menu>
    </el-header>
    
    <!-- 移动版顶部导航 -->
    <el-header class="header mobile-only">
      <div class="logo">AI绘画工作流</div>
      <el-button icon-only @click="drawerVisible = true">
        <el-icon><Menu /></el-icon>
      </el-button>
    </el-header>
    
    <el-main class="main" :class="{ 'has-bottom-nav': isMobileView }">
      <router-view />
    </el-main>
    
    <!-- 移动版侧边导航抽屉 -->
    <el-drawer
      v-model="drawerVisible"
      title="菜单"
      direction="ltr"
      size="70%"
      class="mobile-drawer"
    >
      <el-menu
        :router="true"
        :default-active="route.path"
      >
        <el-menu-item index="/">
          <el-icon><House /></el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-menu-item index="/workflow/list">
          <el-icon><Management /></el-icon>
          <span>工作流管理</span>
        </el-menu-item>
        <el-divider />
        <el-menu-item index="/user/profile" v-if="false">
          <el-icon><User /></el-icon>
          <span>个人中心</span>
        </el-menu-item>
        <el-menu-item index="/user/settings" v-if="false">
          <el-icon><Setting /></el-icon>
          <span>设置</span>
        </el-menu-item>
      </el-menu>
    </el-drawer>
    
    <!-- 移动端底部导航 -->
    <MobileNavBar v-if="isMobileView" />
  </el-container>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { useRoute } from 'vue-router'
import { Menu, House, Management, User, Setting } from '@element-plus/icons-vue'
import MobileNavBar from '@/components/MobileNavBar.vue'

const route = useRoute()
const drawerVisible = ref(false)
const windowWidth = ref(window.innerWidth)

// 监听窗口大小变化
const handleResize = () => {
  windowWidth.value = window.innerWidth
}

onMounted(() => {
  window.addEventListener('resize', handleResize)
})

onUnmounted(() => {
  window.removeEventListener('resize', handleResize)
})

// 判断是否为移动视图
const isMobileView = computed(() => {
  return windowWidth.value <= 768 // 与responsive.scss中的sm断点一致
})
</script>

<style lang="scss" scoped>
@use '@/assets/styles/responsive.scss' as responsive;

.layout-container {
  height: 100%;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--el-border-color-light);
  
  @include responsive.respond-to('xs') {
    padding: 0 12px;
  }
}

.logo {
  font-size: 20px;
  font-weight: bold;
  margin-right: 40px;
  
  @include responsive.respond-to('sm') {
    font-size: 18px;
    margin-right: 0;
  }
}

.desktop-menu {
  flex: 1;
}

.main {
  background: var(--el-bg-color-page);
  padding: 0;
  
  &.has-bottom-nav {
    padding-bottom: 56px; // 为底部导航留出空间
  }
}

.mobile-drawer {
  :deep(.el-drawer__header) {
    margin-bottom: 16px;
    padding: 16px;
  }
  
  :deep(.el-drawer__body) {
    padding: 0;
  }
  
  :deep(.el-menu-item) {
    height: 50px;
    line-height: 50px;
    
    .el-icon {
      margin-right: 12px;
    }
  }
}
</style> 